<?php echo $javascript->link('tooltip'); ?> 
<?php
echo $this->Session->flash();

App::Import('model', 'Poll');
App::Import('model', 'InitialEvaluation');
App::Import('model', 'EvaluationAppraisal');
App::Import('model', 'EvaluationPhysiographicUnit');
App::Import('model', 'EvaluationAnnex');
App::Import('model', 'TopographicMap');
App::Import('model', 'TopographicArea');


$poll = new Poll();
$poll->recursive = -1;
$encuesta = $poll->find('first', array('conditions' => array('Poll.proyect_id' => $proyect_id), 'fields' => array('Poll.id')));
$encuesta['Poll']['id'];
?>
<script>
    mayusculas();
    $(document).ready(function() {
        $( "#biodiv" ).tabs();
        $('#lista_predios').load('<?php echo $html->url(array('controller' => 'properties', 'action' => 'initial_evaluation_index', $proyect_id)) ?>');
        $('#lineas').load('<?php echo $html->url(array('controller' => 'productiveLines', 'action' => 'index', $this->data['InitialEvaluation']['id'])) ?>');
        $('#credito').load('<?php echo $html->url(array('controller' => 'productiveLines', 'action' => 'credit_index', $this->data['InitialEvaluation']['id'])) ?>');
        $('#planos').load('<?php echo $html->url(array('controller' => 'properties', 'action' => 'index_topographic_map')) ?>');
        // $('#ambiental').load('<?php echo $html->url(array('controller' => 'Polls', 'action' => 'ambiental')) ?>');
        $('#biopoll').load('<?php echo $html->url(array('controller' => 'Polls', 'action' => 'climate')) ?>');
        $('#waters').load('<?php echo (!empty($encuesta['Poll']['id'])) ? $html->url(array('controller' => 'WaterPolls', 'action' => 'index', $encuesta['Poll']['id'])) : "" ?>');
        $('#vocacion').load('<?php echo (!empty($encuesta['Poll']['id'])) ? $html->url(array('controller' => 'ProductiveVocations', 'action' => 'index', $encuesta['Poll']['id'])) : "" ?>');
        $('#soils').load('<?php echo $html->url(array('controller' => 'Polls', 'action' => 'soils')) ?>');
        $('#families').load('<?php echo $html->url(array('controller' => 'InitialEvaluations', 'action' => 'families', $this->data['InitialEvaluation']['id'], $proyect_id)) ?>');
        $( "#accordion" ).accordion();
        $( "#accordion" ).accordion( "option", "autoHeight", true );
        $( "#accordion" ).accordion({ collapsible: true });  
        $( "#accordion" ).accordion({ active: false });       
        $('.txtarea,input').tinyTips('title');
    }
)
</script>
<div id="accordion" >
    <h3><a href="#">Información Predios</a></h3>
    <div id="">
        <div id="lista_predios">
        </div>
        <?php echo $form->create('InitialEvaluation'); ?>
        <?php echo $form->hidden("InitialEvaluation.id") ?>
        <fieldset>
            <legend>
                <h2>¿Los datos de ubicación de los predios (Municipio,departamento,vereda,propietarios relacionados) coinciden con los de fase I ?</h2>
            </legend>

            <?php echo $form->input("InitialEvaluation.predio_ubicacion_calificacion", array('label' => '', 'title' => '', 'options' => array('Sin registro' => 'Sin registro', 'Cumple' => 'Cumple', 'Subsanable' => 'Subsanable', ))); ?>
            <?php echo $form->input("InitialEvaluation.predio_ubicacion_concepto", array('label' => '', 'class' => 'txtarea', 'title' => "verificar los datos correspondientes al registro del proyecto en cuanto a ubicación geográfica: departamento, municipio, vereda, nombre del predio, matrícula inmobiliaria, área topográfica, valor de negociación, propietarios y demás relacionados que se encuentren en la información reportada en la Fase I y Fase IIa y relacionada en el Formulario N° 8 (Fase IIb)")); ?>

        </fieldset>
        <fieldset><legend><h2>¿Los datos de identificación de el (los) predio(s), nombre  ,matricula inmobliaria ,cédula catastral coinciden con los de fase I ?)</h2></legend>

            <?php echo $form->input("InitialEvaluation.predio_identificacion_calificacion", array('label' => '', 'options' => array('Sin registro' => 'Sin registro', 'Cumple' => 'Cumple', 'Subsanable' => 'Subsanable', ))); ?>
            <?php echo $form->input("InitialEvaluation.predio_identificacion_concepto", array('label' => 'Concepto del profesional', 'class' => 'txtarea', 'title' => "verificar los datos correspondientes al registro del proyecto en cuanto a ubicación geográfica: departamento, municipio, vereda, nombre del predio, matrícula inmobiliaria, área topográfica, valor de negociación, propietarios y demás relacionados que se encuentren en la información reportada en la Fase I y Fase IIa y relacionada en el Formulario N° 8 (Fase IIb)")); ?>

        </fieldset>

        <?php
        if (($this->Session->read('estado') == 0) and ($usuario['User']['group_id'] == 1 or $usuario['User']['group_id'] == 7 or $usuario['User']['group_id'] == 15))
            echo $ajax->submit('Guardar', array('url' => array('controller' => 'InitialEvaluations', 'action' => 'edit', $this->data['InitialEvaluation']['id'], $proyect_id), 'update' => 'content', 'indicator' => 'loading'));
        ?>
        <?php echo $form->end(); ?> 
    </div> 
    <h3><a>Precio del (los) predio(s)</a></h3>
    <div>
        <table id="tabla">
            <tr><td>Predio</td><td>Valor predio:</td></tr>

            <?php
            $avaluos = new EvaluationAppraisal();
            $avaluos->recursive = -1;
            $suma_avaluos = 0;
            $valor_form_tres = $avaluos->Property->Proyect->field('predio_valor', array('Proyect.id' => $proyect_id));

            foreach ($properties as $prop):
                ?>
                <?php
                $initialEvaluation = new InitialEvaluation();

                $options['joins'] = array(
                    array('table' => 'initial_evaluation_annexes',
                        'alias' => 'InitialEvaluationAnnex',
                        'type' => 'left',
                        'conditions' => array('InitialEvaluation.id = InitialEvaluationAnnex.initial_evaluation_id')),
                    array('table' => 'evaluation_appraisals',
                        'alias' => 'EvaluationAppraisal',
                        'type' => 'left',
                        'conditions' => array('InitialEvaluationAnnex.evaluation_appraisal_id = EvaluationAppraisal.id')),
                    array('table' => 'properties',
                        'alias' => 'Property',
                        'type' => 'left',
                        'conditions' => array('EvaluationAppraisal.property_id = Property.id'))
                );

                $options['conditions'] = array('InitialEvaluation.id' => $this->data['InitialEvaluation']['id'], 'Property.id' => $prop['Property']['id']);
                $options['fields'] = array('EvaluationAppraisal.id');
                $idAvaluo = $initialEvaluation->find('first', $options);

                //Busco el avaluo asociados al predio y a la evaluación inicial y lo sumo a la variable $totalAreaAvaluos para luego mostrar el total del avaluo del proyecto.
                $avaluos = new EvaluationAppraisal();
                $avaluos->recursive = -1;

                $avaluo = $avaluos->find('first', array('conditions' => array('id' => $idAvaluo['EvaluationAppraisal']['id']), 'fields' => array('EvaluationAppraisal.valor', 'EvaluationAppraisal.id')));

                $nom = $prop['Property']['nombre'];
                $valor = $avaluo['EvaluationAppraisal']['valor'];
                $suma_avaluos+=$avaluo['EvaluationAppraisal']['valor']
                ?>

                <tr><td><?php echo $nom ?></td><td><?php echo "$" . number_format($valor, 2, ',', '.') ?></td></tr>
            <?php endforeach; ?>
            <tr><td>Valor total Avalúo comercial:</td><td><?php echo "$" . number_format($suma_avaluos, 2, ',', '.') ?></td></tr>
            <tr><td>Valor en formulario tres</td><td><?php echo "$" . number_format($valor_form_tres, 2, ',', '.') ?></td></tr>
        </table>

        <fieldset></legend>

            <?php echo $form->create('InitialEvaluation'); ?>
            <?php echo $form->hidden("InitialEvaluation.id") ?>
            <?php echo $form->input("InitialEvaluation.calificacion_valor_avaluo", array('label' => '', 'options' => array('Sin registro' => 'Sin registro', 'Cumple' => 'Cumple', 'Subsanable' => 'Subsanable', ))); ?>
            <?php echo $form->input("InitialEvaluation.valor_avaluo", array('label' => 'Valor de negociación', 'title' => "Valor de negociación del  formulario N°8.  ")); ?>
            <?php echo $form->input("InitialEvaluation.concepto_valor_avaluo", array('label' => 'Concepto del profesional', 'class' => 'txtarea', 'title' => "Corroborar el valor total del avaluó, frente al valor de la negociación, que se encuentra consignado dentro del Formulario 3, entregado en la Fase I de la convocatoria. En dado caso que el valor del avalúo comercial sea inferior al reportado en el formulario N° 3 hacer el ajuste en formulario N°8. ")); ?>
            <?php
            if (($this->Session->read('estado') == 0) and ($usuario['User']['group_id'] == 1 or $usuario['User']['group_id'] == 7 or $usuario['User']['group_id'] == 15))
                echo $ajax->submit('Guardar', array('url' => array('controller' => 'InitialEvaluations', 'action' => 'edit', $this->data['InitialEvaluation']['id'], $proyect_id), 'update' => 'content', 'indicator' => 'loading'));
            ?>
            <?php echo $form->end(); ?> 
        </fieldset>

    </div>
    <h3><a href="#">Áreas productivas</a></h3>
    <div>

        <h1>Avalúo:</h1>    
        <?php
        echo $this->Session->flash();

        $totalAreaAvaluos = 0;
        $totalValorAvaluos = 0;
        $totalAreaUtil = 0;
        $totalAreaNoUtil = 0;
        for ($j = 1; $j <= 16; $j++) {
            $totalClase[$j] = 0;
        }
        $valorTotalUnidadesFisiograficas = 0;
        $valorTotalAnexos = 0;
        ?>

        <div id="loading" style="display: none;">
            <?php echo $html->image('loading.gif', array('border' => "0", 'align' => 'center')); ?>
        </div>

        <table  id="tabla" class="tabla" >
            <thead>
                <tr>
                    <th>Código</th>
                    <th>Nombre</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($properties as $prop): ?>
                    <tr>
                        <td><?php
                //Busco el ultimo avaluo del predio y lo sumo a la variable $totalAreaAvaluos para luego mostrar el total del avaluo del proyecto.
                $avaluos = new EvaluationAppraisal();
                $avaluos->recursive = -1;


                $initialEvaluation = new InitialEvaluation();

                $options['joins'] = array(
                    array('table' => 'initial_evaluation_annexes',
                        'alias' => 'InitialEvaluationAnnex',
                        'type' => 'left',
                        'conditions' => array('InitialEvaluation.id = InitialEvaluationAnnex.initial_evaluation_id')),
                    array('table' => 'evaluation_appraisals',
                        'alias' => 'EvaluationAppraisal',
                        'type' => 'left',
                        'conditions' => array('InitialEvaluationAnnex.evaluation_appraisal_id = EvaluationAppraisal.id')),
                    array('table' => 'properties',
                        'alias' => 'Property',
                        'type' => 'left',
                        'conditions' => array('EvaluationAppraisal.property_id = Property.id'))
                );

                $options['conditions'] = array('InitialEvaluation.id' => $this->data['InitialEvaluation']['id'], 'Property.id' => $prop['Property']['id']);
                $options['fields'] = array('EvaluationAppraisal.id');
                $idAvaluo = $initialEvaluation->find('first', $options);

                //Busco el avaluo asociados al predio y a la evaluación inicial y lo sumo a la variable $totalAreaAvaluos para luego mostrar el total del avaluo del proyecto.
                $avaluos = new EvaluationAppraisal();
                $avaluos->recursive = -1;

                $avaluo = $avaluos->find('first', array('conditions' => array('id' => $idAvaluo['EvaluationAppraisal']['id']), 'fields' => array('EvaluationAppraisal.valor', 'EvaluationAppraisal.id', 'EvaluationAppraisal.area')));
                $unidadesFisiograficas = new EvaluationPhysiographicUnit();
                $unidadesFisiograficas->recursive = 0;
                $valorTotalUnidadesFisiograficas += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.valor_unitario * EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id']));
                $anexos = new EvaluationAnnex();
                $anexos->recursive = 0;
                $valorTotalAnexos += $anexos->field('Sum(EvaluationAnnex.magnitud * EvaluationAnnex.valor_unitario)', array('EvaluationAnnex.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id']));
                for ($i = 1; $i <= 16; $i++) {
                    switch ($i) {
                        case 1:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'I', 'EvaluationPhysiographicUnit.util' => 'SI'));
                            break;
                        case 2:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'II', 'EvaluationPhysiographicUnit.util' => 'SI'));
                            break;
                        case 3:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'III', 'EvaluationPhysiographicUnit.util' => 'SI'));
                            break;
                        case 4:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'IV', 'EvaluationPhysiographicUnit.util' => 'SI'));
                            break;
                        case 5:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'V', 'EvaluationPhysiographicUnit.util' => 'SI'));
                            break;
                        case 6:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'VI', 'EvaluationPhysiographicUnit.util' => 'SI'));
                            break;
                        case 7:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'VII', 'EvaluationPhysiographicUnit.util' => 'SI'));
                            break;
                        case 8:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'I', 'EvaluationPhysiographicUnit.util' => 'NO'));
                            break;
                        case 9:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'II', 'EvaluationPhysiographicUnit.util' => 'NO'));
                            break;
                        case 10:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'III', 'EvaluationPhysiographicUnit.util' => 'NO'));
                            break;
                        case 11:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'IV', 'EvaluationPhysiographicUnit.util' => 'NO'));
                            break;
                        case 12:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'V', 'EvaluationPhysiographicUnit.util' => 'NO'));
                            break;
                        case 13:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'VI', 'EvaluationPhysiographicUnit.util' => 'NO'));
                            break;
                        case 14:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'VII', 'EvaluationPhysiographicUnit.util' => 'NO'));
                            break;
                        case 15:
                            //clase agrologica VIII util
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'VIII', 'EvaluationPhysiographicUnit.util' => 'SI'));
                            break;
                        case 16:
                            //clase agrologica VIII no util
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'VIII', 'EvaluationPhysiographicUnit.util' => 'NO'));
                            break;
                    }
                }
                $totalAreaAvaluos += $avaluo['EvaluationAppraisal']['area'];
                $totalValorAvaluos += $avaluo['EvaluationAppraisal']['valor'];
                //Imprimo el codigo del predio
                echo $prop['Property']['codigo']
                    ?></td>
                        <td><?php echo $prop['Property']['nombre'] ?></td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
        <br>
        <br>
        <br>
        <table border="0" id="tabla">
            <thead>
                <tr>
                    <th>Clasificación agrológica</th>
                    <th>Área (ha)</th>
                    <th>Porcentaje %</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>I útil</td>
                    <td><?php echo ($totalClase[1] > 0 and !empty($totalClase[1])) ? number_format($totalClase[1], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[1] > 0) ? number_format(($totalClase[1] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>I no útil</td>
                    <td><?php echo ($totalClase[8] > 0 and !empty($totalClase[8])) ? number_format($totalClase[8], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[8] > 0) ? number_format(($totalClase[8] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>II útil</td>
                    <td><?php echo ($totalClase[2] > 0 and !empty($totalClase[2])) ? number_format($totalClase[2], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[2] > 0) ? number_format(($totalClase[2] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>II no útil</td>
                    <td><?php echo ($totalClase[9] > 0 and !empty($totalClase[9])) ? number_format($totalClase[9], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[9] > 0) ? number_format(($totalClase[9] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>III útil</td>
                    <td><?php echo ($totalClase[3] > 0 and !empty($totalClase[3])) ? number_format($totalClase[3], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[3] > 0) ? number_format(($totalClase[3] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>III no útil</td>
                    <td><?php echo ($totalClase[10] > 0 and !empty($totalClase[10])) ? number_format($totalClase[10], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[10] > 0) ? number_format(($totalClase[10] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>IV útil</td>
                    <td><?php echo ($totalClase[4] > 0 and !empty($totalClase[4])) ? number_format($totalClase[4], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[4] > 0) ? number_format(($totalClase[4] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>IV no útil</td>
                    <td><?php echo ($totalClase[11] > 0 and !empty($totalClase[11])) ? number_format($totalClase[11], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[11] > 0) ? number_format(($totalClase[11] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>V útil</td>
                    <td><?php echo ($totalClase[5] > 0 and !empty($totalClase[5])) ? number_format($totalClase[5], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[5] > 0) ? number_format(($totalClase[5] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>V no útil</td>
                    <td><?php echo ($totalClase[12] > 0 and !empty($totalClase[12])) ? number_format($totalClase[12], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[12] > 0) ? number_format(($totalClase[12] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>        </tr>
                <tr>
                    <td>VI útil</td>
                    <td><?php echo ($totalClase[6] > 0 and !empty($totalClase[6])) ? number_format($totalClase[6], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[6] > 0) ? number_format(($totalClase[6] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>VI no útil</td>
                    <td><?php echo ($totalClase[13] > 0 and !empty($totalClase[13])) ? number_format($totalClase[13], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[13] > 0) ? number_format(($totalClase[13] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>VII útil</td>
                    <td><?php echo ($totalClase[7] > 0 and !empty($totalClase[7])) ? number_format($totalClase[7], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[7] > 0) ? number_format(($totalClase[7] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>VII no útil</td>
                    <td><?php echo ($totalClase[14] > 0 and !empty($totalClase[14])) ? number_format($totalClase[14], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[14] > 0) ? number_format(($totalClase[14] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>VIII útil</td>
                    <td><?php echo ($totalClase[15] > 0 and !empty($totalClase[15])) ? number_format($totalClase[15], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[15] > 0) ? number_format(($totalClase[15] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>VIII no útil</td>
                    <td><?php echo ($totalClase[16] > 0 and !empty($totalClase[16])) ? number_format($totalClase[16], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[16] > 0) ? number_format(($totalClase[16] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
            </tbody>
        </table>

        <table border="0" id="tabla">
            <thead>
                <tr>
                    <th></th>
                    <th>Área (ha)</th>
                    <th>Porcentaje %</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Útil</td>
                    <td><?php
                for ($i = 1; $i <= 7; $i++) {
                    $totalAreaUtil += $totalClase[$i];
                }
                $totalAreaUtil += $totalClase[15];
                echo number_format($totalAreaUtil, 2, ',', '.') . " (ha)"
                ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0) ? number_format(($totalAreaUtil * 100 / $totalAreaAvaluos), 2, ',', '.') . " %" : "0 %" ?></td>
                </tr>
                <tr>
                    <td>No útil</td>
                    <td><?php
                        for ($i = 8; $i <= 14; $i++) {
                            $totalAreaNoUtil += $totalClase[$i];
                        }
                        $totalAreaNoUtil += $totalClase[16];
                        echo number_format($totalAreaNoUtil, 2, ',', '.') . " (ha)"
                ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0) ? number_format(($totalAreaNoUtil * 100 / $totalAreaAvaluos), 2, ',', '.') . " %" : "0 %" ?></td>
                </tr>
            </tbody>
        </table>
        <table class="tabla" >
            <thead>
                <tr>
                    <th>Área total avaluos</th>
                    <th>Área total unidades fisiograficas</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td <?php echo ((round($totalAreaAvaluos, 4) != round(($totalAreaNoUtil + $totalAreaUtil), 4)) ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?>><?php echo $totalAreaAvaluos . ' (ha)' ?></td>
                    <td <?php echo ((round($totalAreaAvaluos, 4) != round(($totalAreaNoUtil + $totalAreaUtil), 4)) ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?>><?php echo number_format(($totalAreaNoUtil + $totalAreaUtil), 4, '.', ',') . ' (ha)' ?></td>
                </tr>
            </tbody>
        </table>
        <table class="tabla" >
            <thead>
                <tr>
                    <th>Valor total unidades fisiograficas</th>
                    <th>% unidades</th>
                    <th>Valor total anexos</th>
                    <th>% anexos</th>
                    <th>Valor anexos + unidades fisiograficas</th>
                    <th>Valor avaluos</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td <?php echo (($totalValorAvaluos != ($valorTotalAnexos + $valorTotalUnidadesFisiograficas) or ($valorTotalAnexos + $valorTotalUnidadesFisiograficas == 0)) ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?> ><?php echo "$" . number_format($valorTotalUnidadesFisiograficas, 2, ',', '.') ?></td>
                    <td <?php echo (($totalValorAvaluos != ($valorTotalAnexos + $valorTotalUnidadesFisiograficas) or ($valorTotalAnexos + $valorTotalUnidadesFisiograficas == 0)) ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?> ><?php echo ($valorTotalAnexos + $valorTotalUnidadesFisiograficas) > 0 ? number_format(($valorTotalUnidadesFisiograficas * 100 / ($valorTotalAnexos + $valorTotalUnidadesFisiograficas)), 2, ',', '.') . "%" : "" ?></td>
                    <td <?php echo (($totalValorAvaluos != ($valorTotalAnexos + $valorTotalUnidadesFisiograficas) or ($valorTotalAnexos + $valorTotalUnidadesFisiograficas == 0)) ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?> ><?php echo "$" . number_format($valorTotalAnexos, 2, ',', '.') ?></td>
                    <td <?php echo (($totalValorAvaluos != ($valorTotalAnexos + $valorTotalUnidadesFisiograficas) or ($valorTotalAnexos + $valorTotalUnidadesFisiograficas == 0)) ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?> ><?php echo ($valorTotalAnexos + $valorTotalUnidadesFisiograficas) > 0 ? number_format(($valorTotalAnexos * 100 / ($valorTotalAnexos + $valorTotalUnidadesFisiograficas)), 2, ',', '.') . "%" : "" ?></td>
                    <td <?php echo (($totalValorAvaluos != ($valorTotalAnexos + $valorTotalUnidadesFisiograficas) or ($valorTotalAnexos + $valorTotalUnidadesFisiograficas == 0)) ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?> ><?php echo "$" . number_format(($valorTotalAnexos + $valorTotalUnidadesFisiograficas), 2, ',', '.') ?></td>
                    <td <?php echo (($totalValorAvaluos != ($valorTotalAnexos + $valorTotalUnidadesFisiograficas) or ($valorTotalAnexos + $valorTotalUnidadesFisiograficas == 0)) ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?> ><?php echo "$" . number_format($totalValorAvaluos, 2, ',', '.') ?></td>
                </tr>
            </tbody>
        </table>

        <h1>Plano topográfico:</h1>
        <?php
        $totalAreaPlano = 0;
        $totalAreaUtil = 0;
        $totalAreaNoUtil = 0;
        ?>
        <table id="tabla" >
            <thead>
                <tr>
                    <th>Código</th>
                    <th>Nombre</th>
                    <th>Área total (ha)</th>
                    <th>Área útil (ha)</th>
                    <th>%</th>
                    <th>Área no útil (ha)</th>
                    <th>%</th>
                </tr>
            </thead>
            <tbody>
                <?php
                foreach ($properties as $prop):

                    $initialEvaluation = new InitialEvaluation();
                    $options = array();

                    $options['joins'] = array(
                        array('table' => 'initial_evaluation_annexes',
                            'alias' => 'InitialEvaluationAnnex',
                            'type' => 'left',
                            'conditions' => array('InitialEvaluation.id = InitialEvaluationAnnex.initial_evaluation_id')),
                        array('table' => 'topographic_maps',
                            'alias' => 'TopographicMap',
                            'type' => 'left',
                            'conditions' => array('InitialEvaluationAnnex.topographic_map_id = TopographicMap.id')),
                        array('table' => 'properties',
                            'alias' => 'Property',
                            'type' => 'left',
                            'conditions' => array('TopographicMap.property_id = Property.id'))
                    );

                    $options['conditions'] = array('InitialEvaluation.id' => $this->data['InitialEvaluation']['id'], 'Property.id' => $prop['Property']['id']);
                    $options['fields'] = array('TopographicMap.id');
                    $idPlano = $initialEvaluation->find('first', $options);

                    //Busco el ultimo plano topografico y lo sumo a la variable $totalAreaPlano para luego mostrar el total del area de los planos del proyecto.
                    $planos = new TopographicMap();
                    $planos->recursive = -1;

                    $plano = $planos->find('first', array('conditions' => array('TopographicMap.id' => $idPlano['TopographicMap']['id']), 'fields' => array('TopographicMap.id', 'TopographicMap.area')));
                    //sumo al total del proyecto
                    $totalAreaPlano += $plano['TopographicMap']['area'];
                    //Traigo el total de las areas utiles y no utiles
                    $areas = new TopographicArea();
                    $areas->recursive = 0;
                    $areaTotalUtil = $areas->field('Sum(TopographicArea.magnitud)', array('TopographicArea.topographic_map_id' => $plano['TopographicMap']['id'], 'AreaType.productiva' => 1));
                    $areaTotalNoUtil = $areas->field('Sum(TopographicArea.magnitud)', array('TopographicArea.topographic_map_id' => $plano['TopographicMap']['id'], 'AreaType.productiva' => 0));
                    $totalAreaNoUtil += $areaTotalNoUtil;
                    $totalAreaUtil += $areaTotalUtil;

                    $error = (( round(($areaTotalUtil + $areaTotalNoUtil), 2) != round($plano['TopographicMap']['area'], 2) ) or $plano['TopographicMap']['area'] < 0 or empty($plano['TopographicMap']['area']) ) ? true : false;
                    ?>
                    <tr>
                        <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8;'") ?>>
                            <?php echo $prop['Property']['codigo'] ?>
                        </td>
                        <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?> >
                            <?php echo $prop['Property']['nombre'] ?></td>
                        <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?>>
                            <?php echo number_format($plano['TopographicMap']['area'], 2, ',', '.') ?></td>
                        <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?> >
                            <?php echo number_format($areaTotalUtil, 2, ',', '.') ?></td>
                        <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?>>
                            <?php echo (($plano['TopographicMap']['area'] > 0) ? number_format(($areaTotalUtil * 100) / ($plano['TopographicMap']['area']), 2, ',', '.') . "%" : "" ) ?></td>
                        <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?> >
                            <?php echo number_format($areaTotalNoUtil, 2, ',', '.') ?></td>
                        <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?> >
                            <?php echo (($plano['TopographicMap']['area'] > 0) ? number_format(($areaTotalNoUtil * 100) / ($plano['TopographicMap']['area']), 2, ',', '.') . "%" : "" ) ?></td>
                    </tr>
                <?php endforeach; ?>
                <tr>
                    <td></td>
                    <td><b>Área total (ha)</b></td>
                    <td><?php echo $totalAreaPlano . ' (ha)' ?></td>
                    <td><?php echo number_format($totalAreaUtil, 2, ',', '.') . ' (ha)' ?></td>
                    <td><?php echo ($totalAreaPlano > 0) ? number_format((($totalAreaUtil * 100) / $totalAreaPlano), 2, ',', '.') . ' %' : "0 %" ?></td>
                    <td><?php echo number_format($totalAreaNoUtil, 2, ',', '.') . ' (ha)' ?></td>
                    <td><?php echo ($totalAreaPlano > 0) ? number_format((($totalAreaNoUtil * 100) / $totalAreaPlano), 2, ',', '.') . ' %' : "0 %" ?></td>
                </tr>
            </tbody>
        </table>
        <br>
        <fieldset><legend><h2> </h2></legend>
            <?php echo $form->create('InitialEvaluation'); ?>
            <?php echo $form->hidden("InitialEvaluation.id") ?>
            <?php echo $form->input("InitialEvaluation.area_productiva_calificacion", array('label' => '', 'options' => array('Sin registro' => 'Sin registro', 'Cumple' => 'Cumple', 'Subsanable' => 'Subsanable', ))); ?>
            <?php echo $form->input("InitialEvaluation.area_productiva_concepto", array('label' => 'Concepto del profesional', 'class' => 'txtarea', 'title' => "Comparar el área productiva expresada en número absoluto y porcentaje cotejada con lo descrito tanto en el plano topográfico (revisar áreas improductivas) como en el avalúo comercial (verificar clasificación agrológica). Se debe tener en cuenta que el área propuesta para el desarrollo del proyecto productivo no sea superior al área total del predio.")); ?>
            <?php
            if (($this->Session->read('estado') == 0) and ($usuario['User']['group_id'] == 1 or $usuario['User']['group_id'] == 7 or $usuario['User']['group_id'] == 15))
                echo $ajax->submit('Guardar', array('url' => array('controller' => 'InitialEvaluations', 'action' => 'edit', $this->data['InitialEvaluation']['id'], $proyect_id), 'update' => 'content', 'indicator' => 'loading'));
            ?>
            <?php echo $form->end(); ?> 
        </fieldset>
    </div>

    <h3><a>Construcciones y anexos</a></h3>
    <div>
        <table id ="tabla">
            <thead>
                <tr>
                    <th>Tipo</th>
                    <th>Magnitud</th>
                    <th>Unidad de medida</th>
                    <th>Valor total</th>
                    <th>¿Es mejora útil?</th>
                    <th>Descripción</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($properties as $prop): ?>
                    <?php
                    //Busco el ultimo avaluo del predio y lo sumo a la variable $totalAreaAvaluos para luego mostrar el total del avaluo del proyecto.
                    $avaluos = new EvaluationAppraisal();
                    $avaluos->recursive = -1;

                    $initialEvaluation = new InitialEvaluation();

                    $options['joins'] = array(
                        array('table' => 'initial_evaluation_annexes',
                            'alias' => 'InitialEvaluationAnnex',
                            'type' => 'left',
                            'conditions' => array('InitialEvaluation.id = InitialEvaluationAnnex.initial_evaluation_id')),
                        array('table' => 'evaluation_appraisals',
                            'alias' => 'EvaluationAppraisal',
                            'type' => 'left',
                            'conditions' => array('InitialEvaluationAnnex.evaluation_appraisal_id = EvaluationAppraisal.id')),
                        array('table' => 'properties',
                            'alias' => 'Property',
                            'type' => 'left',
                            'conditions' => array('EvaluationAppraisal.property_id = Property.id'))
                    );

                    $options['conditions'] = array('InitialEvaluation.id' => $this->data['InitialEvaluation']['id'], 'Property.id' => $prop['Property']['id']);
                    $options['fields'] = array('EvaluationAppraisal.id');
                    $idAvaluo = $initialEvaluation->find('first', $options);

                    //$avaluo = $avaluos->find('first', array('conditions' => array('EvaluationAppraisal.property_id' => $prop['Property']['id']), 'order' => array('EvaluationAppraisal.id DESC'), 'fields' => array('EvaluationAppraisal.id', 'EvaluationAppraisal.area', 'EvaluationAppraisal.valor')));
                    $avaluo = $avaluos->find('first', array('conditions' => array('EvaluationAppraisal.id' => $idAvaluo['EvaluationAppraisal']['id']), 'fields' => array('EvaluationAppraisal.id', 'EvaluationAppraisal.area', 'EvaluationAppraisal.valor')));
                    $anexos = new EvaluationAnnex();
                    $anexos->recursive = 0;
                    $anexos2 = $anexos->find('all', array('conditions' => array('EvaluationAnnex.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id']), 'order' => array('EvaluationAnnex.id DESC'), 'fields' => array('EvaluationAnnex.id', 'EvaluationAnnex.item', 'EvaluationAnnex.magnitud', 'EvaluationAnnex.valor_unitario', 'EvaluationAnnex.mejora_util', 'EvaluationAnnex.descripcion', 'EvaluationAnnex.unidad_medida')));
                    ?> 
                    <?php foreach ($anexos2 as $annex): ?>
                        <tr>
                            <td>
                                <?php echo $annex['EvaluationAnnex']['item'] ?>
                            </td>
                            <td>
                                <?php echo number_format($annex['EvaluationAnnex']['magnitud'], 2, ',', '.') ?>
                            </td>
                            <td>
                                <?php echo $annex['EvaluationAnnex']['unidad_medida'] ?>
                            </td>
                            <td>
                                <?php echo "$ " . number_format($annex['EvaluationAnnex']['magnitud'] * $annex['EvaluationAnnex']['valor_unitario'], 2, ',', '.') ?>
                            </td>
                            <td>
                                <?php echo $annex['EvaluationAnnex']['mejora_util'] ?>
                            </td>
                            <td>
                                <?php echo $annex['EvaluationAnnex']['descripcion'] ?>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                <?php endforeach; ?>
            </tbody>
        </table>

        <fieldset>
            <?php echo $form->create('InitialEvaluation'); ?>
            <?php echo $form->hidden("InitialEvaluation.id") ?>  
            <?php echo $form->input("InitialEvaluation.construcciones_calificacion", array('label' => '', 'options' => array('Sin registro' => 'Sin registro', 'Cumple' => 'Cumple', 'Subsanable' => 'Subsanable', ))); ?>
            <?php echo $form->input("InitialEvaluation.construcciones_concepto", array('label' => 'Concepto del profesional', 'class' => 'txtarea', 'title' => "Constatar que las construcciones y anexos con que cuenta (n) el (los) predio (s) avaluado (s) comercialmente estén incluidos en la formulación del proyecto productivo, en caso contrario, solicitar ajustes  para que sea aprovechada la infraestructura existente.")); ?>
            <?php
            if (($this->Session->read('estado') == 0) and ($usuario['User']['group_id'] == 1 or $usuario['User']['group_id'] == 7 or $usuario['User']['group_id'] == 15))
                echo $ajax->submit('Guardar', array('url' => array('controller' => 'InitialEvaluations', 'action' => 'edit', $this->data['InitialEvaluation']['id'], $proyect_id), 'update' => 'content', 'indicator' => 'loading'));
            ?>
            <?php echo $form->end(); ?> 
        </fieldset> 

    </div>

    <h3><a href="#">Área del proyecto productivo formulado</a></h3>
    <div>
        <table id="tabla" >
            <thead>
                <tr>
                    <th>Código</th>
                    <th>Nombre</th>
                    <th>Área total (ha)</th>
                    <th>Área útil (ha)</th>
                    <th>%</th>
                    <th>Área no útil (ha)</th>
                    <th>%</th>
                </tr>
            </thead>
            <tbody>
                <?php
                $totalAreaUtil = 0;
                $areaTotalUtil = 0;
                $totalAreaNoUtil = 0;
                $totalAreaPlano = 0;
                foreach ($properties as $prop):
                    //Busco el plano topografico asociado y lo sumo a la variable $totalAreaPlano para luego mostrar el total del area de los planos del proyecto.
                    $initialEvaluation = new InitialEvaluation();
                    $options = array();
                    $options['joins'] = array(
                        array('table' => 'initial_evaluation_annexes',
                            'alias' => 'InitialEvaluationAnnex',
                            'type' => 'left',
                            'conditions' => array('InitialEvaluation.id = InitialEvaluationAnnex.initial_evaluation_id')),
                        array('table' => 'topographic_maps',
                            'alias' => 'TopographicMap',
                            'type' => 'left',
                            'conditions' => array('InitialEvaluationAnnex.topographic_map_id = TopographicMap.id')),
                        array('table' => 'properties',
                            'alias' => 'Property',
                            'type' => 'left',
                            'conditions' => array('TopographicMap.property_id = Property.id'))
                    );
                    $options['conditions'] = array('InitialEvaluation.id' => $this->data['InitialEvaluation']['id'], 'Property.id' => $prop['Property']['id']);
                    $options['fields'] = array('TopographicMap.id');
                    $idPlano = $initialEvaluation->find('first', $options);

                    //Busco el plano topografico asociado a esta evaluación inicial y lo sumo a la variable $totalAreaPlano para luego mostrar el total del area de los planos del proyecto.
                    $planos = new TopographicMap();
                    $planos->recursive = -1;

                    $plano = $planos->find('first', array('conditions' => array('TopographicMap.id' => $idPlano['TopographicMap']['id']), 'fields' => array('TopographicMap.id', 'TopographicMap.area')));

                    //sumo al total del proyecto
                    $totalAreaPlano += $plano['TopographicMap']['area'];
                    //Traigo el total de las areas utiles y no utiles
                    $areas = new TopographicArea();
                    $areas->recursive = 0;
                    $areaTotalUtil = $areas->field('Sum(TopographicArea.magnitud)', array('TopographicArea.topographic_map_id' => $plano['TopographicMap']['id'], 'AreaType.productiva' => 1));
                    $areaTotalNoUtil = $areas->field('Sum(TopographicArea.magnitud)', array('TopographicArea.topographic_map_id' => $plano['TopographicMap']['id'], 'AreaType.productiva' => 0));
                    $totalAreaNoUtil += $areaTotalNoUtil;
                    $totalAreaUtil += $areaTotalUtil;

                    $error = (( round(($areaTotalUtil + $areaTotalNoUtil), 2) != round($plano['TopographicMap']['area'], 2) ) or $plano['TopographicMap']['area'] < 0 or empty($plano['TopographicMap']['area']) ) ? true : false;
                    ?>
                    <tr>
                        <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8;'") ?>>
                            <?php echo $prop['Property']['codigo'] ?>
                        </td>
                        <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?> >
                            <?php echo $prop['Property']['nombre'] ?></td>
                        <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?>>
                            <?php echo number_format($plano['TopographicMap']['area'], 2, ',', '.') ?></td>
                        <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?> >
                            <?php echo number_format($areaTotalUtil, 2, ',', '.') ?></td>
                        <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?>>
                            <?php echo (($plano['TopographicMap']['area'] > 0) ? number_format(($areaTotalUtil * 100) / ($plano['TopographicMap']['area']), 2, ',', '.') . "%" : "" ) ?></td>
                        <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?> >
                            <?php echo number_format($areaTotalNoUtil, 2, ',', '.') ?></td>
                        <td <?php echo ($error ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?> >
                            <?php echo (($plano['TopographicMap']['area'] > 0) ? number_format(($areaTotalNoUtil * 100) / ($plano['TopographicMap']['area']), 2, ',', '.') . "%" : "" ) ?></td>
                    </tr>
                <?php endforeach; ?>
                <tr>
                    <td></td>
                    <td><b>Área total (ha)</b></td>
                    <td><?php echo number_format($totalAreaPlano, 2, ',', '.') . ' (ha)' ?></td>
                    <td><?php echo number_format($totalAreaUtil, 2, ',', '.') . ' (ha)' ?></td>
                    <td><?php echo ($totalAreaPlano > 0) ? number_format((($totalAreaUtil * 100) / $totalAreaPlano), 2, ',', '.') . ' %' : "0 %" ?></td>
                    <td><?php echo number_format($totalAreaNoUtil, 2, ',', '.') . ' (ha)' ?></td>
                    <td><?php echo ($totalAreaPlano > 0) ? number_format((($totalAreaNoUtil * 100) / $totalAreaPlano), 2, ',', '.') . ' %' : "0 %" ?></td>

                </tr>
            </tbody>
        </table>
        <br>
        <fieldset><legend><h2>Área del proyecto productivo formulado. </h2></legend>
            <?php echo $form->create('InitialEvaluation'); ?>
            <?php echo $form->hidden("InitialEvaluation.id") ?>
            <?php echo $form->input("InitialEvaluation.calificacion_areas_explotacion", array('label' => '', 'options' => array('Sin registro' => 'Sin registro', 'Cumple' => 'Cumple', 'Subsanable' => 'Subsanable', ))); ?>
            <?php echo $form->input("InitialEvaluation.area_explotacion_actual", array('label' => 'Total área explotación actual (ha)', 'title' => "En el numeral 5.1 Explotación actual y proyectada del predio revisar Total Área de explotación actual y explotación proyectada  para los cultivos propuestos; debido a que el proyecto productivo se realizo sin contar con el levantamiento topográfico ni el avaluó comercial, se debe corroborar que las variables de estos documentos concuerden con las áreas del plano topográfico.")); ?>
            <?php echo $form->input("InitialEvaluation.area_explotacion_proyectada", array('label' => 'Total área explotación proyectada (ha)',)); ?>
            <?php echo $form->input("InitialEvaluation.concepto_areas_explotacion", array('label' => 'Concepto del profesional', 'class' => 'txtarea', 'title' => " En el numeral 5.1 Explotación actual y proyectada del predio, revisar el total área de explotación actual y explotación proyectada para los cultivos propuestos; debido a que el proyecto productivo se realizó sin contar con el levantamiento topográfico ni el avaluó comercial. Se debe corroborar que las variables de estos documentos concuerden.")); ?>
            <?php
            if (($this->Session->read('estado') == 0) and ($usuario['User']['group_id'] == 1 or $usuario['User']['group_id'] == 7 or $usuario['User']['group_id'] == 15))
                echo $ajax->submit('Guardar', array('url' => array('controller' => 'InitialEvaluations', 'action' => 'edit', $this->data['InitialEvaluation']['id'], $proyect_id), 'update' => 'content', 'indicator' => 'loading'));
            ?>
            <?php echo $form->end(); ?> 
        </fieldset>

    </div>

    <h3><a>Compatibilidad del proyecto productivo respecto a lo descrito en el formularios 6  y 7 </a></h3>
    <div>
        <div id="ambiental">

        </div>
        <?php echo $form->create('InitialEvaluation'); ?>
        <?php echo $form->hidden("InitialEvaluation.id") ?>
        <?php echo $form->input("InitialEvaluation.formularios_calificacion", array('label' => '', 'options' => array('Sin registro' => 'Sin registro', 'Cumple' => 'Cumple', 'Subsanable' => 'Subsanable', ))); ?>
        <?php echo $form->input("InitialEvaluation.formularios_concepto", array('label' => 'Concepto del profesional', 'class' => 'txtarea', 'title' => "Revisar que los usos expuestos en el certificado de uso de suelo (formulario 6) y el certificado de exclusión del predio del SINAP (formulario 7 ); Verificando que el proyecto cumpla con las políticas de conservación del medio ambiente y de los recursos renovables (sostenibilidad ). Formularios adjuntos en la fase I")); ?>
        <?php
        if (($this->Session->read('estado') == 0) and ($usuario['User']['group_id'] == 1 or $usuario['User']['group_id'] == 7 or $usuario['User']['group_id'] == 15))
            echo $ajax->submit('Guardar', array('url' => array('controller' => 'InitialEvaluations', 'action' => 'edit', $this->data['InitialEvaluation']['id'], $proyect_id), 'update' => 'content', 'indicator' => 'loading'));
        ?>
        <?php echo $form->end(); ?>  
    </div>
    <h3><a>Explotación Agropecuaria </a></h3>
    <div>

        <h1>Avalúo:</h1>    
        <?php
        $totalAreaAvaluos = 0;
        $totalValorAvaluos = 0;
        $totalAreaUtil = 0;
        $totalAreaNoUtil = 0;
        for ($j = 1; $j <= 16; $j++) {
            $totalClase[$j] = 0;
        }
        $valorTotalUnidadesFisiograficas = 0;
        $valorTotalAnexos = 0;
        ?>

        <table  id="tabla" class="tabla" >
            <thead>
                <tr>
                    <th>Código</th>
                    <th>Nombre</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($properties as $prop): ?>
                    <tr>
                        <td><?php
                //Busco el ultimo avaluo del predio y lo sumo a la variable $totalAreaAvaluos para luego mostrar el total del avaluo del proyecto.
                $avaluos = new EvaluationAppraisal();
                $avaluos->recursive = -1;

                $initialEvaluation = new InitialEvaluation();

                $options['joins'] = array(
                    array('table' => 'initial_evaluation_annexes',
                        'alias' => 'InitialEvaluationAnnex',
                        'type' => 'left',
                        'conditions' => array('InitialEvaluation.id = InitialEvaluationAnnex.initial_evaluation_id')),
                    array('table' => 'evaluation_appraisals',
                        'alias' => 'EvaluationAppraisal',
                        'type' => 'left',
                        'conditions' => array('InitialEvaluationAnnex.evaluation_appraisal_id = EvaluationAppraisal.id')),
                    array('table' => 'properties',
                        'alias' => 'Property',
                        'type' => 'left',
                        'conditions' => array('EvaluationAppraisal.property_id = Property.id'))
                );

                $options['conditions'] = array('InitialEvaluation.id' => $this->data['InitialEvaluation']['id'], 'Property.id' => $prop['Property']['id']);
                $options['fields'] = array('EvaluationAppraisal.id');
                $idAvaluo = $initialEvaluation->find('first', $options);

                //Busco el avaluo asociados al predio y a la evaluación inicial y lo sumo a la variable $totalAreaAvaluos para luego mostrar el total del avaluo del proyecto.
                $avaluos = new EvaluationAppraisal();
                $avaluos->recursive = -1;

                $avaluo = $avaluos->find('first', array('conditions' => array('id' => $idAvaluo['EvaluationAppraisal']['id']), 'fields' => array('EvaluationAppraisal.valor', 'EvaluationAppraisal.id', 'EvaluationAppraisal.area')));

                $unidadesFisiograficas = new EvaluationPhysiographicUnit();
                $unidadesFisiograficas->recursive = 0;
                $valorTotalUnidadesFisiograficas += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.valor_unitario * EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id']));
                $anexos = new EvaluationAnnex();
                $anexos->recursive = 0;
                $valorTotalAnexos += $anexos->field('Sum(EvaluationAnnex.magnitud * EvaluationAnnex.valor_unitario)', array('EvaluationAnnex.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id']));
                for ($i = 1; $i <= 16; $i++) {
                    switch ($i) {
                        case 1:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'I', 'EvaluationPhysiographicUnit.util' => 'SI'));
                            break;
                        case 2:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'II', 'EvaluationPhysiographicUnit.util' => 'SI'));
                            break;
                        case 3:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'III', 'EvaluationPhysiographicUnit.util' => 'SI'));
                            break;
                        case 4:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'IV', 'EvaluationPhysiographicUnit.util' => 'SI'));
                            break;
                        case 5:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'V', 'EvaluationPhysiographicUnit.util' => 'SI'));
                            break;
                        case 6:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'VI', 'EvaluationPhysiographicUnit.util' => 'SI'));
                            break;
                        case 7:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'VII', 'EvaluationPhysiographicUnit.util' => 'SI'));
                            break;
                        case 8:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'I', 'EvaluationPhysiographicUnit.util' => 'NO'));
                            break;
                        case 9:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'II', 'EvaluationPhysiographicUnit.util' => 'NO'));
                            break;
                        case 10:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'III', 'EvaluationPhysiographicUnit.util' => 'NO'));
                            break;
                        case 11:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'IV', 'EvaluationPhysiographicUnit.util' => 'NO'));
                            break;
                        case 12:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'V', 'EvaluationPhysiographicUnit.util' => 'NO'));
                            break;
                        case 13:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'VI', 'EvaluationPhysiographicUnit.util' => 'NO'));
                            break;
                        case 14:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'VII', 'EvaluationPhysiographicUnit.util' => 'NO'));
                            break;
                        case 15:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'VIII', 'EvaluationPhysiographicUnit.util' => 'SI'));
                            break;
                        case 16:
                            $totalClase[$i] += $unidadesFisiograficas->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $avaluo['EvaluationAppraisal']['id'], 'EvaluationPhysiographicUnit.clase_agrologica' => 'VIII', 'EvaluationPhysiographicUnit.util' => 'NO'));
                            break;
                    }
                }
                $totalAreaAvaluos += $avaluo['EvaluationAppraisal']['area'];
                $totalValorAvaluos += $avaluo['EvaluationAppraisal']['valor'];
                //Imprimo el codigo del predio
                echo $prop['Property']['codigo']
                    ?></td>
                        <td><?php echo $prop['Property']['nombre'] ?></td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
        <br>
        <table border="0" id="tabla">
            <thead>
                <tr>
                    <th>Clasificación agrológica</th>
                    <th>Área (ha)</th>
                    <th>Porcentaje %</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>I útil</td>
                    <td><?php echo ($totalClase[1] > 0 and !empty($totalClase[1])) ? number_format($totalClase[1], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[1] > 0) ? number_format(($totalClase[1] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>I no útil</td>
                    <td><?php echo ($totalClase[8] > 0 and !empty($totalClase[8])) ? number_format($totalClase[8], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[8] > 0) ? number_format(($totalClase[8] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>II útil</td>
                    <td><?php echo ($totalClase[2] > 0 and !empty($totalClase[2])) ? number_format($totalClase[2], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[2] > 0) ? number_format(($totalClase[2] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>II no útil</td>
                    <td><?php echo ($totalClase[9] > 0 and !empty($totalClase[9])) ? number_format($totalClase[9], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[9] > 0) ? number_format(($totalClase[9] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>III útil</td>
                    <td><?php echo ($totalClase[3] > 0 and !empty($totalClase[3])) ? number_format($totalClase[3], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[3] > 0) ? number_format(($totalClase[3] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>III no útil</td>
                    <td><?php echo ($totalClase[10] > 0 and !empty($totalClase[10])) ? number_format($totalClase[10], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[10] > 0) ? number_format(($totalClase[10] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>IV útil</td>
                    <td><?php echo ($totalClase[4] > 0 and !empty($totalClase[4])) ? number_format($totalClase[4], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[4] > 0) ? number_format(($totalClase[4] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>IV no útil</td>
                    <td><?php echo ($totalClase[11] > 0 and !empty($totalClase[11])) ? number_format($totalClase[11], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[11] > 0) ? number_format(($totalClase[11] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>V útil</td>
                    <td><?php echo ($totalClase[5] > 0 and !empty($totalClase[5])) ? number_format($totalClase[5], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[5] > 0) ? number_format(($totalClase[5] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>V no útil</td>
                    <td><?php echo ($totalClase[12] > 0 and !empty($totalClase[12])) ? number_format($totalClase[12], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[12] > 0) ? number_format(($totalClase[12] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>        </tr>
                <tr>
                    <td>VI útil</td>
                    <td><?php echo ($totalClase[6] > 0 and !empty($totalClase[6])) ? number_format($totalClase[6], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[6] > 0) ? number_format(($totalClase[6] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>VI no útil</td>
                    <td><?php echo ($totalClase[13] > 0 and !empty($totalClase[13])) ? number_format($totalClase[13], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[13] > 0) ? number_format(($totalClase[13] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>VII útil</td>
                    <td><?php echo ($totalClase[7] > 0 and !empty($totalClase[7])) ? number_format($totalClase[7], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[7] > 0) ? number_format(($totalClase[7] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>VII no útil</td>
                    <td><?php echo ($totalClase[14] > 0 and !empty($totalClase[14])) ? number_format($totalClase[14], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[14] > 0) ? number_format(($totalClase[14] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>VIII útil</td>
                    <td><?php echo ($totalClase[15] > 0 and !empty($totalClase[15])) ? number_format($totalClase[15], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[15] > 0) ? number_format(($totalClase[15] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
                <tr>
                    <td>VIII no útil</td>
                    <td><?php echo ($totalClase[16] > 0 and !empty($totalClase[16])) ? number_format($totalClase[16], 2, ',', '.') : "-" ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0 and $totalClase[16] > 0) ? number_format(($totalClase[16] * 100 / $totalAreaAvaluos), 2, ',', '.') : "-" ?></td>
                </tr>
            </tbody>
        </table>

        <table border="0" id="tabla">
            <thead>
                <tr>
                    <th></th>
                    <th>Área (ha)</th>
                    <th>Porcentaje %</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Útil</td>
                    <td><?php
                for ($i = 1; $i <= 7; $i++) {
                    $totalAreaUtil += $totalClase[$i];
                }
                $totalAreaUtil += $totalClase[15];
                echo number_format($totalAreaUtil, 2, ',', '.') . " (ha)"
                ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0) ? number_format(($totalAreaUtil * 100 / $totalAreaAvaluos), 2, ',', '.') . " %" : "0 %" ?></td>
                </tr>
                <tr>
                    <td>No útil</td>
                    <td><?php
                        for ($i = 8; $i <= 14; $i++) {
                            $totalAreaNoUtil += $totalClase[$i];
                        }
                        $totalAreaNoUtil += $totalClase[16];
                        echo number_format($totalAreaNoUtil, 2, ',', '.') . " (ha)"
                ?></td>
                    <td><?php echo ($totalAreaAvaluos > 0) ? number_format(($totalAreaNoUtil * 100 / $totalAreaAvaluos), 2, ',', '.') . " %" : "0 %" ?></td>
                </tr>
            </tbody>
        </table>
        <table class="tabla" >
            <thead>
                <tr>
                    <th>Área total avaluos</th>
                    <th>Área total unidades fisiograficas</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td <?php echo ((round($totalAreaAvaluos, 4) != round(($totalAreaNoUtil + $totalAreaUtil), 4)) ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?>><?php echo number_format($totalAreaAvaluos, 4, '.', ',') . ' (ha)' ?></td>
                    <td <?php echo ((round($totalAreaAvaluos, 4) != round(($totalAreaNoUtil + $totalAreaUtil), 4)) ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?>><?php echo number_format(($totalAreaNoUtil + $totalAreaUtil), 4, '.', ',') . ' (ha)' ?></td>
                </tr>
            </tbody>
        </table>
        <table class="tabla" >
            <thead>
                <tr>
                    <th>Valor total unidades fisiograficas</th>
                    <th>% unidades</th>
                    <th>Valor total anexos</th>
                    <th>% anexos</th>
                    <th>Valor anexos + unidades fisiograficas</th>
                    <th>Valor avaluos</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td <?php echo (($totalValorAvaluos != ($valorTotalAnexos + $valorTotalUnidadesFisiograficas) or ($valorTotalAnexos + $valorTotalUnidadesFisiograficas == 0)) ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?> ><?php echo "$" . number_format($valorTotalUnidadesFisiograficas, 2, ',', '.') ?></td>
                    <td <?php echo (($totalValorAvaluos != ($valorTotalAnexos + $valorTotalUnidadesFisiograficas) or ($valorTotalAnexos + $valorTotalUnidadesFisiograficas == 0)) ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?> ><?php echo ($valorTotalAnexos + $valorTotalUnidadesFisiograficas) > 0 ? number_format(($valorTotalUnidadesFisiograficas * 100 / ($valorTotalAnexos + $valorTotalUnidadesFisiograficas)), 2, ',', '.') . "%" : "" ?></td>
                    <td <?php echo (($totalValorAvaluos != ($valorTotalAnexos + $valorTotalUnidadesFisiograficas) or ($valorTotalAnexos + $valorTotalUnidadesFisiograficas == 0)) ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?> ><?php echo "$" . number_format($valorTotalAnexos, 2, ',', '.') ?></td>
                    <td <?php echo (($totalValorAvaluos != ($valorTotalAnexos + $valorTotalUnidadesFisiograficas) or ($valorTotalAnexos + $valorTotalUnidadesFisiograficas == 0)) ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?> ><?php echo ($valorTotalAnexos + $valorTotalUnidadesFisiograficas) > 0 ? number_format(($valorTotalAnexos * 100 / ($valorTotalAnexos + $valorTotalUnidadesFisiograficas)), 2, ',', '.') . "%" : "" ?></td>
                    <td <?php echo (($totalValorAvaluos != ($valorTotalAnexos + $valorTotalUnidadesFisiograficas) or ($valorTotalAnexos + $valorTotalUnidadesFisiograficas == 0)) ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?> ><?php echo "$" . number_format(($valorTotalAnexos + $valorTotalUnidadesFisiograficas), 2, ',', '.') ?></td>
                    <td <?php echo (($totalValorAvaluos != ($valorTotalAnexos + $valorTotalUnidadesFisiograficas) or ($valorTotalAnexos + $valorTotalUnidadesFisiograficas == 0)) ? "style='background-color: #F79F81;'" : "style='background-color: #81F7D8'") ?> ><?php echo "$" . number_format($totalValorAvaluos, 2, ',', '.') ?></td>
                </tr>
            </tbody>
        </table>
        <fieldset>
            <?php echo $form->create('InitialEvaluation'); ?>
            <?php echo $form->hidden("InitialEvaluation.id") ?>
            <?php echo $form->input("InitialEvaluation.explotacion_agraria_calificacion", array('label' => '', 'options' => array('Sin registro' => 'Sin registro', 'Cumple' => 'Cumple', 'Subsanable' => 'Subsanable', ))); ?>
            <?php echo $form->input("InitialEvaluation.explotacion_agraria_concepto", array('label' => 'Concepto del profesional', 'class' => 'txtarea', 'title' => "La explotación agraria propuesta sea pertinente con la clasificación agrológica determinada para el (los) predio (s), no superando el 20% de las clases agrológicas VII y VIII no fértiles.")); ?>
            <?php
            if (($this->Session->read('estado') == 0) and ($usuario['User']['group_id'] == 1 or $usuario['User']['group_id'] == 7 or $usuario['User']['group_id'] == 15))
                echo $ajax->submit('Guardar', array('url' => array('controller' => 'InitialEvaluations', 'action' => 'edit', $this->data['InitialEvaluation']['id'], $proyect_id), 'update' => 'content', 'indicator' => 'loading'));
            ?>
            <?php echo $form->end(); ?> 
        </fieldset>
    </div>

    <h3><a>Vocación productiva</a></h3>
    <div>
        
        <fieldset>
            <?php echo $form->create('InitialEvaluation'); ?>
            <?php echo $form->hidden("InitialEvaluation.id") ?>
            <?php echo $form->input("InitialEvaluation.vocacion_productiva_calificacion", array('label' => '', 'options' => array('Sin registro' => 'Sin registro', 'Cumple' => 'Cumple', 'Subsanable' => 'Subsanable', ))); ?>
            <?php echo $form->input("InitialEvaluation.vocacion_productiva_concepto", array('label' => 'Concepto del profesional', 'class' => 'txtarea', 'title' => "Revisar la vocación productiva del predio condiciones edafoclimáticas e infraestructura existente con relación a la información recolectada en la Fase II a encuesta socio-productiva.")); ?>
            <?php
            if (($this->Session->read('estado') == 0) and ($usuario['User']['group_id'] == 1 or $usuario['User']['group_id'] == 7 or $usuario['User']['group_id'] == 15))
                echo $ajax->submit('Guardar', array('url' => array('controller' => 'InitialEvaluations', 'action' => 'edit', $this->data['InitialEvaluation']['id'], $proyect_id), 'update' => 'content', 'indicator' => 'loading'));
            ?>
            <?php echo $form->end(); ?> 
        </fieldset>


    </div>
    <h3><a>Asistencia técnica</a></h3>
    <div>
        <fieldset>

            <?php echo $form->create('InitialEvaluation'); ?>
            <?php echo $form->hidden("InitialEvaluation.id") ?>

            <table border="1">
z
                <tbody>
                    <tr>
                        <td>Calificación</td>
                        <td><?php echo $form->input("InitialEvaluation.asistencia_calificacion", array('label' => '', 'options' => array('Sin registro' => 'Sin registro', 'Cumple' => 'Cumple', 'Subsanable' => 'Subsanable', ))); ?></td>
                    </tr>
                    <tr>
                        <td>Entidad:</td>
                        <td><?php echo $form->input("InitialEvaluation.asistencia_entidad", array('label' => '', 'title' => 'Nombre de la entidad encargada de prestar la asistencia técnica')); ?></td>
                    </tr>
                    <tr>
                        <td>Representante legal:</td>
                        <td><?php echo $form->input("InitialEvaluation.asistencia_representante", array('label' => '', 'title' => 'Nombre de la entidad encargada de prestar la asistencia técnica')); ?></td>
                    </tr>

                    <tr>
                        <td>Profesional formulador:</td>
                        <td> <?php echo $form->input("InitialEvaluation.asistencia_formulador", array('label' => '', 'title' => 'Nombre del profesional formulador')); ?>
                    </tr>
                    <tr>
                        <td>Presenta carta de acompañamiento:</td>
                        <td><?php echo $form->input("InitialEvaluation.asistencia_carta_acompanamiento", array('label' => '', 'options' => array('Sin registro' => 'Sin registro', 'Si' => 'Si', 'No' => 'No'), 'title' => '¿Presenta la carta de acompañamiento?')); ?></td>  
                    </tr>
                    <tr>

                        <td colspan="2" > <?php echo $form->input("InitialEvaluation.asistencia_concepto", array('label' => '', 'class' => 'txtarea', 'title' => "Revisar en el Formulario 8 que la ejecución del proyecto cuente con una entidad pública o privada encargada de asesorar a los beneficiarios del subsidio y prestar la asistencia técnica requerida para su desarrollo; revisar si existe carta de certificación de asistencia técnica, si no está adjunta solicitarla.")); ?></td>                
                    </tr>
                </tbody>
            </table>
            <fieldset/>
            <?php
            if (($this->Session->read('estado') == 0) and ($usuario['User']['group_id'] == 1 or $usuario['User']['group_id'] == 7 or $usuario['User']['group_id'] == 15))
                echo $ajax->submit('Guardar', array('url' => array('controller' => 'InitialEvaluations', 'action' => 'edit', $this->data['InitialEvaluation']['id'], $proyect_id), 'update' => 'content', 'indicator' => 'loading'));
            ?>
            <?php echo $form->end(); ?> 
    </div>
    <h3><a>Lineas productivas</a></h3>
    <div>
        <div id="lineas"></div>
    </div>
    <h3><a>Información finaciera</a></h3>
    <div>
        <div id="credito">
        </div>
        <?php echo $form->create('InitialEvaluation'); ?>
        <?php echo $form->hidden("InitialEvaluation.id") ?>
        <?php echo $form->input("InitialEvaluation.componente_financiero_calificacion", array('label' => '¿Presenta planificación de credito', 'options' => array('Sin registro' => 'Sin registro', 'Cumple' => 'Cumple', 'Subsanable' => 'Subsanable', ))); ?>
        <?php echo $form->input("InitialEvaluation.tir", array('label' => 'Tasa interna de retorno (TIR)', 'title' => "Vaslor TIR")); ?>
        <?php echo $form->input("InitialEvaluation.cabida_familiar", array('label' => 'Cabida  familiar', 'title' => "valor cabida familiar")); ?>
        <?php echo $form->input("InitialEvaluation.generacion_ingresos", array('label' => 'Generación de ingresos (SMMV)', 'title' => "Valor Generación de ingresos")); ?>
        <?php echo $form->input("InitialEvaluation.carta_intencion", array('label' => 'Carta de intención de compra', 'options' => array('Sin registro' => 'Sin registro', 'Si' => 'Si', 'No' => 'No'), 'title' => "	Revisar si adjuntan cartas de intención de compra de los productos propuestos en la explotación agropecuaria")); ?>
        <?php echo $form->input("InitialEvaluation.componente_financiero_calificacion", array('label' => 'Calificacion de los aspectos financieros', 'options' => array('Sin registro' => 'Sin registro', 'Cumple' => 'Cumple', 'Subsanable' => 'Subsanable', ))); ?>
        <?php echo $form->input("InitialEvaluation.componente_financiero_concepto", array('label' => 'Concepto del profesional', 'class' => 'txtarea', 'title' => "Revisar que esté dentro del Formulario N° 8 la planificación de crédito, requisito indispensable para aspirar hasta el 40% como subsidio del valor total del proyecto productivo. Revisar los valores de crédito, cabida familiar, Tasa Interna de Retorno y generación de ingresos (SMMLV) en el modelo financiero, de acuerdo a lo establecido en los Términos de Referencia.	Revisar si adjuntan cartas de intención de compra de los productos propuestos en la explotación agropecuaria. Este concepto se emite de acuerdo a la información ingresada  ")); ?>
        <?php
        if (($this->Session->read('estado') == 0) and ($usuario['User']['group_id'] == 1 or $usuario['User']['group_id'] == 7 or $usuario['User']['group_id'] == 15))
            echo $ajax->submit('Guardar', array('url' => array('controller' => 'InitialEvaluations', 'action' => 'edit', $this->data['InitialEvaluation']['id'], $proyect_id), 'update' => 'content', 'indicator' => 'loading'));
        ?>
        <?php echo $form->end(); ?> 

    </div>

    <h3><a>Familias</a></h3>

    <div id="families">

    </div>

    <h3><a>Concepto Integral</a></h3>
    <div>
        <?php echo $form->create('InitialEvaluation'); ?>
        <?php echo $form->hidden("InitialEvaluation.id") ?>
        <?php echo $form->input("InitialEvaluation.calificacion_integral", array('label' => '', 'options' => array('Sin registro' => 'Sin registro', 'Cumple' => 'Cumple', 'Subsanable' => 'Subsanable', ))); ?>
        <?php echo $form->input("InitialEvaluation.concepto_integral", array('label' => 'Concepto del profesional', 'class' => 'txtarea', 'title' => "Constatar los indicadores en el Modelo Único Financiero MUF, que se ajusten al número de familias aspirantes a subsidios de la convocatoria SIT, teniendo en cuenta la estimación del tamaño del proyecto productivo para que el resultado corresponda a los S.M.M.L.V. y a la cabida familiar requerida con el fin de evitar la desfinanciación del proyecto por efecto de créditos sobredimensionados, por lo tanto solicitar aclaraciones y ajustes técnicos en las líneas productivas planteadas.")); ?>
        <?php echo $form->input("InitialEvaluation.observacion_integral", array('label' => 'Observación del profesional', 'class' => 'txtarea')); ?>
        <?php
        if (($this->Session->read('estado') == 0) and ($usuario['User']['group_id'] == 1 or $usuario['User']['group_id'] == 7 or $usuario['User']['group_id'] == 15))
            echo $ajax->submit('Guardar', array('url' => array('controller' => 'InitialEvaluations', 'action' => 'edit', $this->data['InitialEvaluation']['id'], $proyect_id), 'update' => 'content', 'indicator' => 'loading'));
        ?>
        <?php echo $form->end(); ?> 

    </div>
</div> 

<table width="100%" border="0"  CellSpacing=10  align="center" >

    <tbody>
        <tr>
            <td><?php echo $ajax->link($html->image('regresar.gif', array('width' => '30', 'heigth' => '30', 'alt' => 'Regresar', 'title' => 'regresar')), array('controller' => 'InitialEvaluations', 'action' => 'index'), array('update' => 'content', 'indicator' => 'loading', 'escape' => false)); ?></td>
        </tr>
    </tbody>
</table>